home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
gnu
/
progutil
/
stdwin.zoo
/
tools
/
strdup.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-29
|
964b
|
68 lines
/* Save a copy of a string. */
#include "configure.h"
#ifdef LSC
/* Function prototypes */
#include <proto.h>
char *strdup(char *str);
char *strndup(char *str, int n);
#else
#ifdef __STDC__
#include <stddef.h>
#include <string.h>
#include <memory.h>
#ifndef NULL
#define NULL ((void *)0)
#endif
void *malloc(size_t);
char *strcpy(char *, const char *), *strncpy(char *, const char *, size_t);
#else
#define NULL 0
char *malloc(), *strcpy(), *strncpy();
#endif
#endif
#if !defined(atarist) && !defined(__GNUC__)
char *
strdup(str)
#ifdef __STDC__
const
#endif
char *str;
{
char *copy= NULL;
if (str != NULL) {
copy= malloc((size_t) (strlen(str) + 1));
if (copy != NULL)
strcpy(copy, str);
}
return copy;
}
#endif
char *
strndup(str, len)
char *str;
int len;
{
char *copy= NULL;
if (str != NULL) {
copy= malloc((size_t) (len + 1));
if (copy != NULL) {
strncpy(copy, str, (size_t)len);
copy[len]= '\0';
}
}
return copy;
}